public class DichotomySearch {

    public static int search(int[] n,int tar){
        int left=0;
        int rigrh=n.length-1;
        while (left<=rigrh){
            int mid=(left+rigrh)/2;
            if(n[mid]>tar){
                rigrh=mid-1;
            }else if (n[mid]<tar){
                left=mid+1;
            }else {
                return mid;
            }


        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {-1,0,3,5,9,12};
        System.out.println(search(nums,0));
    }
}
